package com.basic.library.Interface;

import com.google.gson.internal.$Gson$Types;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * @author jiangyun
 * @description
 * @time 创建时间：2018/3/26 10:11
 */
public abstract class BusCallback<T> {
    public abstract void onBusChanged(T t);

    public Type mType;
    public String[] key;

    public BusCallback(String... key) {
        mType = getSuperclassTypeParameter(getClass());
        this.key = key;
    }

    private static Type getSuperclassTypeParameter(Class<?> subclass) {
        Type superclass = subclass.getGenericSuperclass();
        if (superclass instanceof Class) {
            throw new RuntimeException("Missing type parameter.");
        }
        ParameterizedType parameterized = (ParameterizedType) superclass;
        return $Gson$Types.canonicalize(parameterized.getActualTypeArguments()[0]);
    }
}
